// UeObjectId.h: interface for the UeObjectId class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_UEOBJECTID_H__4CBDD229_8349_4BB0_A51D_CC60164D7D56__INCLUDED_)
#define AFX_UEOBJECTID_H__4CBDD229_8349_4BB0_A51D_CC60164D7D56__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "SmallObject.h"
#include "afxtempl.h"

class AFX_EXT_CLASS ObjectId : public SmallObject 
{
public:
	ObjectId(){
		m_lObjectId = 0;
	}
	ObjectId(unsigned long lId){
		m_lObjectId = lId;
	}

	ObjectId(const ObjectId& id){
		m_lObjectId = id.m_lObjectId;
	}

	virtual ~ObjectId(){}

public:
	BOOL IsNull() const {
		return m_lObjectId == 0;
	}

	const ObjectId& operator=(const ObjectId& other){
		if(this == &other)
			return *this;
		m_lObjectId = other.m_lObjectId;
		return *this;
	}

	const ObjectId& operator=(unsigned long id){
		m_lObjectId = id;
		return *this;
	}

	BOOL operator==(const ObjectId& id) const {
		return m_lObjectId == id.m_lObjectId;
	}

	BOOL operator!=(const ObjectId& id) const {
		return m_lObjectId != id.m_lObjectId;
	}

	BOOL operator==(unsigned long id) const {
		return m_lObjectId == id;
	}

	BOOL operator!=(unsigned long id) const {
		return m_lObjectId != id;
	}

	BOOL operator==(INT id) const {
		return m_lObjectId == id;
	}

	BOOL operator!=(INT id) const {
		return m_lObjectId != id;
	}

	operator INT() const {
		return m_lObjectId;
	}

	operator unsigned long() const {
		return m_lObjectId;
	}
	
private:
	unsigned long m_lObjectId;
};

typedef ObjectId UeObjectId;
typedef CArray<ObjectId, ObjectId> UeObjectIdSet;

SmallObject* GetObject(const UeObjectId& Id);

class Joint;
class Part;
class Volume;
class SupportHanger;

DllExport Joint* Convert(Joint* p, const ObjectId& id);
DllExport Part* Convert(Part* p, const ObjectId& id);
DllExport Volume* Convert(Volume* p, const ObjectId& id);
DllExport SupportHanger* Convert(SupportHanger* p, const ObjectId& id);

template<typename Output> Output* ConvertObjectId(Output* o, const UeObjectId& id)
{
	SmallObject* pObj = GetObject(id);
	if(pObj == NULL)
	{
		ASSERT(pObj);
		return NULL;
	}

	if(pObj->IsKindOf(UE_RUNTIME_CLASS(Output)))
		return (Output*)pObj;

	return NULL;
}


#endif // !defined(AFX_UEOBJECTID_H__4CBDD229_8349_4BB0_A51D_CC60164D7D56__INCLUDED_)
